<?php

namespace Project\ScrumBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class GroupeType extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
                ->add('nom', 'text', array('label' => 'Nom de l\'équipe'))
                ->add('ref_projet', 'entity', array(
                    'class' => 'Project\ScrumBundle\Entity\Projet',
                    'property' => 'nom',
                    'label' => 'Projet : '))
                ->add('utilisateur', 'entity', array(
                    'class' => 'Project\ScrumBundle\Entity\Utilisateur',
                    'property' => 'email',
                    'expanded' => true,
                    'multiple' => true,
                    'label' => 'Client : ',
                    'query_builder' => function (\Doctrine\ORM\EntityRepository $er) {
                        return $er->createQueryBuilder('utilisateur')
                                ->where('utilisateur.refRole != :param')
                                ->andWhere('utilisateur.refRole != :param2')
                                ->setParameters(array('param' => 4, 'param2' => 1)); // 4 = ROLE_CLIENT, 1 = ROLE_ADMIN
                    },
                ));
        ;
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver) {
        $resolver->setDefaults(array(
            'data_class' => 'Project\ScrumBundle\Entity\Groupe'
        ));
    }

    public function getName() {
        return 'project_scrumbundle_groupetype';
    }

}
